using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using DataObject.Core;
using DataObject.Database;

namespace DataObject.DataAccess
{
    public partial class PriceTypeDAO : DataBaseProcessBase<PriceTypeEntity, OBSDataContext>
    {
        public static PriceTypeDAO CreateInstant()
        {
            return new PriceTypeDAO();
        }

        #region Extensibility Method Declarations
        public void InsertCollection(List<PriceTypeEntity> ls)
        {
            using (OBSDataContext db = new OBSDataContext(base.connectionString))
            {
                db.PriceTypeEntities.InsertAllOnSubmit(ls);
                db.SubmitChanges();
            }
        }
        public void Update(PriceTypeEntity item)
        {
            using (OBSDataContext db = new OBSDataContext(base.connectionString))
            {
                db.UpdatePriceType(item.Id, item.Name);
            }
        }
        public List<PriceTypeEntity> GetPriceTypeAll()
        {
            using (OBSDataContext db = new OBSDataContext(base.connectionString))
            {
                return db.PriceTypeEntities.ToList();
            }
        }
        public PriceTypeEntity GetPriceTypeById(string pId)
        {
            using (OBSDataContext db = new OBSDataContext(base.connectionString))
            {
                return db.PriceTypeEntities.SingleOrDefault(a => a.Id.Equals(pId));
            }
        }
        public List<PriceTypeEntity> SelectListItem(string Id, string Name, HashSet<string> SortClause)
        {
            int Count = 0;
            return SelectListItem(Id, Name, null, null, out Count, SortClause);
        }
        public List<PriceTypeEntity> SelectListItem(string Id, string Name, int? Page, int? Row, out int Count, HashSet<string> SortClause)
        {
            using (OBSDataContext db = new OBSDataContext(base.connectionString))
            {
                var query = (from table in db.PriceTypeEntities select table);
                if (!Id.Equals(string.Empty))
                    query = query.Where(table => table.Id.ToLower().Equals(Id.ToLower()));
                if (!Name.Equals(string.Empty))
                    query = query.Where(table => table.Name.ToLower().Equals(Name.ToLower()));
                for (int i = SortClause.Count - 1; i >= 0; i--)
                    query = query.OrderBy(SortClause.ElementAt(i));
                Count = query.Count();
                if (Page.HasValue && Row.HasValue)
                    return query.PageIQuery(Page.Value, Row.Value).ToList();
                return query.ToList();
            }
        }
        #endregion
    }    
}
